<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://photos">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/form.xsl" />
	<xsl:include href="albumBar.xsl" />

	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/photoForms.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<!-- Header -->
			<div id="header">
				<xsl:call-template name="logo" />
				
				<!-- Menu -->
				<xsl:call-template name="menu" />
			</div>
			<!-- /Header -->
			
			<!-- Blocks -->
			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
				</div>
			</div>
			<!-- // Blocks -->
			
			<!-- Content -->
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<!-- // Content -->
			
			<!-- Address -->
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		
		<xsl:apply-templates select="document(concat('xobject://photoalbum/', @album-id))/data/object" mode="album-bar" />
		
		<h1>&labelEditPhotos;</h1>
		
		<form id="edit_photos" method="post" enctype="multipart/form-data">
			<xsl:attribute name="action">
				<xsl:value-of select="concat ($baseURI, '/photos/edit/', @album-id, '/save?', ../@query-string)" />
			</xsl:attribute>
			<xsl:for-each select="form">
				<div class="item">
					<div class="preview">
						<a href="{$baseURI}/photos/photo/{@prefix}">
							<img alt="">
								<xsl:attribute name="src">
									<xsl:value-of select="concat ($baseURI, '/thumb_100_100', field[@name='photo']/value)" />
								</xsl:attribute>
							</img>
							<p id="album_preview_controller_{@prefix}">
								<a href="javascript:void(0);" onclick="setAlbumPreview({../@album-id}, {@prefix});" class="album_preview_controller">&labelAlbumPreview;</a>
							</p>
						</a>
					</div>
					
					<div class="info">
						<div class="field_item">
							<div class="name">&labelAlbum;:</div>
							<div class="input">
								<select>
									<xsl:attribute name="name">
										<xsl:value-of select="concat ('data[', @prefix, '][album_id]')" />
									</xsl:attribute>
								
									<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbumsSelection/', field[@name='album_id']/value))/data/response/object" mode="album-option">
										<xsl:sort select="property[@name='title']/value" />
									</xsl:apply-templates>
									
								</select>
								<xsl:if test="field[@name='album_id']/error != ''">
									<div class="error">
										<xsl:value-of select="field[@name='album_id']/error" />
									</div>
								</xsl:if>
							</div>
						</div>
						<div class="field_item">
							<div class="name">&labelTitle;</div>
							<div class="input">
								<input type="text">
									<xsl:attribute name="name">
										<xsl:value-of select="concat ('data[', @prefix, '][title]')" />
									</xsl:attribute>
									<xsl:attribute name="value">
										<xsl:value-of select="field[@name='title']/value" />
									</xsl:attribute>
								</input>
							</div>
						</div>
						<div class="field_item">
							<div class="name">&labelDescription;:</div>
							<div class="input">
								<textarea>
									<xsl:attribute name="name">
										<xsl:value-of select="concat ('data[', @prefix, '][description]')" />
									</xsl:attribute>
									<xsl:value-of select="field[@name='description']/value" />
								</textarea>
							</div>
						</div>
						<div class="field_item">
							<div class="name">&labelTags;:</div>
							<div class="input">
								<input type="text">
									<xsl:attribute name="name">
										<xsl:value-of select="concat ('data[', @prefix, '][tags]')" />
									</xsl:attribute>
									<xsl:attribute name="value">
										<xsl:value-of select="field[@name='tags']/value" />
									</xsl:attribute>
								</input>
							</div>
						</div>
					</div>
				</div>
			</xsl:for-each>
			
			<p>
				<input type="submit" value="&labelSaveButton;" />
			</p>
		</form>
	</xsl:template>
	
	<!-- ALBUM OPTION -->
	<xsl:template match="object[@type='photoalbum']" mode="album-option">
		<option>
			<xsl:if test="@selected = '1'">
				<xsl:attribute name="selected"><xsl:text>selected</xsl:text></xsl:attribute>
			</xsl:if>
			<xsl:attribute name="value">
				<xsl:value-of select="@id" />
			</xsl:attribute>
			<xsl:value-of select="property[@name='title']/value" />
		</option>
	</xsl:template>
	
</xsl:stylesheet>